namespace NHCodeFirst.Tests
{
    using Enums;

    public class TestContext : DbContext
    {
        public DbSet<Entities.User> Users { get; set; }
        public DbSet<Entities.UserGroup> UserGroups { get; set; }
        public DbSet<Entities.News> News { get; set; }

        protected override void FluentMap(FluentMapper.FluentMapper mapper)
        {
            mapper.Entity<Entities.User>()
                .MapClass(classMapper =>
                          {
                              classMapper.Id(user => user.ID).Generator(IdGenerator.Native);
                              classMapper.Version(user1 => user1.Version).UnsavedValue(null);
                              classMapper.Discriminator.ColumnName("Test");
                              classMapper.BatchSize(200);
                          });
            mapper.Entity<Entities.User>()
                .Property(user1 => user1.Username)
                .NotNull()
                .Lazy(true);
            mapper.Entity<Entities.User>()
                .Component(user => user.Contact)
                .Access(Access.Property).Lazy(true)
                .Property(info => info.Address).Unique(true, "Unique1");
            mapper.Entity<Entities.User>()
                .OneToMany(user2 => user2.News)
                .Cascade(CollectionCascade.AllDeleteOrphan)
                .Inverse(true);
            mapper.Entity<Entities.User>()
                .OneToMany(user3 => user3.News)
                .MapKeys(keyMapper => keyMapper.AddKey("UserID"))
                .Cascade(CollectionCascade.AllDeleteOrphan);
            mapper.Entity<Entities.User>()
                .ManyToMany(user4 => user4.UserGroups, "UsersUserGroup")
                .MapKeys(mapper1 => mapper1.AddKey("UserID"))
                .AddManyColumn("UserGroupID")
                .Fetch(Fetch.Join)
                .NotFound(NotFound.Exception);
            mapper.Entity<Entities.User>()
                .OneToOne(user5 => user5.Profile)
                .PropertyRef(profile => profile.ID)
                .Lazy(true);
        }
    }
}